﻿using System;
using System.IO;
using System.Runtime.Serialization;
using System.Windows.Media;
using System.Windows.Media.Media3D;

namespace GameBoard
{
    [DataContract]
    [KnownType(typeof(BaseTerrainData))]
    [KnownType(typeof(ArrowVisualData))]
    [KnownType(typeof(GridVisualData))]
    [KnownType(typeof(InfoTextVisualData))]
    [KnownType(typeof(MovementCircleVisualData))]
    [KnownType(typeof(PictureVisualData))]
    [KnownType(typeof(ModelVisualData))]
    public abstract class BaseVisualData
    {
        private Brush _brush;

        [DataMember]
        public Guid FactoryID { get; set; }

        [DataMember]
        public Color MaterialColor { get; set; }

        [DataMember]
        public string MaterialFile { get; set; }

        [DataMember]
        internal bool BelongsToMoveablePicture { get; set; }
        
        public Brush MaterialBrush
        {
            get
            {
                return _brush;
            }
            set { _brush = value; }
        }
        public virtual Material Material 
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(MaterialFile))
                {
                    if (File.Exists(MaterialFile))
                    {
                        MaterialBrush = MaterialMaker.MakeImageMaterial(MaterialFile);
                        return new DiffuseMaterial(MaterialBrush);
                    }
                }
                MaterialBrush = new SolidColorBrush(MaterialColor);
                return new DiffuseMaterial(MaterialBrush);
            }
        }


        
    }
}